package cn.javass.dp.factorymethod.demo1;

//常用静态工厂方法，利用static 工具类、一般不需要实例化
//缺点 如果我需要工厂提供新的对象、则需要修改 StaticFactroy

interface Food {

}

class A implements Food {};
class B implements Food {};
class C implements Food {};

public class StaticFactory {

    private StaticFactory() {
    }

    public static Food getA() {return new A(); }
    public static Food getB() {return new B(); }
    public static Food getC() {return new C(); }
    //新增public static Food getD() {return new C(); }


}

class Client {
    Food x= null;

    public void getX(String name) {
        if (name.equals("A")) {
            x =  StaticFactory.getA();
        } else {
            x = StaticFactory.getC();
        }
    }
}

